package com.ljm.msgactivity2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    public static final String EXTRA_MESSAGE="com.foo.neon.MESSAGE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
      //找到事件源
        Button btn= findViewById(R.id.button2);
        //设置事件监听
        btn.setOnClickListener(new View.OnClickListener(){
        @Override
                public void onClick(View v){
                     sendMessage(v);
        }
    });
}
   public void sendMessage(View v){
        Log.i("MyDebug","响应按钮点击事件--");
        //构建意图
      Intent intent=new Intent(this,DisplayMessageMainActivity.class);
      //获取文本框中的数据
       EditText editText=findViewById(R.id.editTextTextPersonName);
       String message=editText.getText().toString();
       intent.putExtra(this.EXTRA_MESSAGE, message);
       //执行意图
       startActivity(intent);
   }
}